<template>
  <div class="login-wrapper">
    <el-dialog
      v-model="props.show"
      title="Login"
      width="500"
      :before-close="handleClose"
    >
      <div>
        <el-form ref="form" :model="formData" label-width="80px">
          <el-form-item label="手机号">
            <el-input v-model="formData.phone"></el-input>
          </el-form-item>
          <el-form-item label="验证码">
            <el-input v-model="formData.code"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="handleClose">Cancel</el-button>
          <el-button type="primary" @click="handleSubmitLogin">
            Confirm
          </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
import { computed, getCurrentInstance, reactive, ref, toRefs, watch } from 'vue'
import { ElMessageBox } from 'element-plus'
import { defineProps } from 'vue'
import { useRouter } from 'vue-router'
import { useLoginStore } from '@/stores/login'
const loginStore = useLoginStore()
const router = useRouter()
const props = defineProps({
  show: Boolean,
})

const showDialog = ref(props.show)
const emits = defineEmits(['close'])
function handleClose() {
  emits('close', false)
}
async function handleSubmitLogin() {
  let isLogin = await loginStore.login(formData)
  router.go(0)
  isLogin && handleClose()
}

const formData = reactive({
  phone: '18018585801',
  code: '9999',
})
</script>

<style lang="scss" scoped></style>
